package com.baomibing.flow.model;

import com.baomibing.core.exception.ServerRuntimeException;
import com.baomibing.flow.constant.NodeTypeEnum;
import com.baomibing.flow.exception.FlowExceptionEnum;
import com.baomibing.flow.execute.Execution;
import com.google.common.collect.Lists;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * StartNode
 *
 * @author frog 2023/9/18 17:18
 * @version 1.0.0
 **/
@Slf4j
@EqualsAndHashCode(callSuper = true)
@ToString
public class StartNode extends WorkNode {

    @Override
    public List<TransitionNode> getInputs() {
        return Lists.newArrayList();
    }

    @Override
    public void execute(Execution execution) {
        log.info("*****process: 正在执行StartNode, 执行人:{}", execution.getActor());
        List<TransitionNode> outputs = getOutputs();
        for (TransitionNode line : outputs) {
            line.execute(execution);
        }
    }

    @Override
    public void reject(Execution execution) {
        throw new ServerRuntimeException(FlowExceptionEnum.START_NODE_CAN_NOT_BE_REJECT);
    }

    public StartNode(String name) {
        this.name = name;
        this.nodeType = NodeTypeEnum.Start.name();
    }

    //for json deserialize
    public StartNode() {
        this.nodeType = NodeTypeEnum.Start.name();
    }
}
